import java.util.ArrayList;

/**
 * @author 赵希奥
 * @date 2022/3/31 1:34
 * @gitHub https://github.com/CKXGZXA
 * @gitee https://gitee.com/ckxgzxa
 * @description: 班级类, 充当容器构建类
 */
public class Class extends SchoolComponent{
    // 存储SchoolComponent类型的成员
    private ArrayList<SchoolComponent> schoolComponents = new ArrayList<>();

    private String name;

    public Class(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public void add(SchoolComponent component) {
        schoolComponents.add(component);
    }

    @Override
    public void remove(SchoolComponent component) {
        schoolComponents.remove(component);
    }

    @Override
    public SchoolComponent getChild(int i) {
        return schoolComponents.get(i);
    }

    @Override
    public void notice() {
        System.out.println("****通知下发到" + name + "班级");

        // 递归调用成员构件的notice方法
        for (SchoolComponent obj : schoolComponents) {
            obj.notice();
        }
    }
}
